#pragma once
/*
    http服务的实现
*/
#include"ThreadPool.hpp"//线程池
#include"TcpServer.hpp"//传输层
#include"Protocol.hpp"//应用层
#include"daemon.hpp"
const char*pwd="/home/ldcwd/";
    static const uint16_t defaultport=8888;//默认端口号
class HttpServer
{   
    private:
    bool quit_;//用来标志服务器是否退出
    uint16_t port_;
    public:
    HttpServer(const uint16_t& port=defaultport)
    :quit_(true),port_(port)
    {}

    //服务器运行起来
    void Loop()
    {
        //守护进程
        Daemon();
        quit_=false;
       TcpServer*tptr= TcpServer::GetInsatnce(port_);
       Sock* listenfd=tptr->GetListenFd();
      ThreadPool*tp= ThreadPool::GetInstance();
        while(!quit_)
        {
            uint16_t poolport;//远端端口号
            std::string poolip;//远端ip
           int fd= listenfd->Accept(&poolport,&poolip);
            if(fd<0)continue;//获取fd失败继续获取
            lg(DEBUG,__LINE__,"Accept success!! fd is %d ,\
            poolip is:%s , poolport is :%d",fd,poolip.c_str(),poolport);
            //获取连接成功，用线程池对连接进行处理
            Task t(fd);
            tp->Push(t);
        }
        quit_=true;
    }
    ~HttpServer(){}
};

